<?php
@header("content-Type: text/html; charset=utf-8");
function calendar($y)
{
    $w=date('w',  strtotime('$y-1-1'));
    $html='';
    for($m=1;$m<=12;++$m){
        $html.='<table>';
        $html.='<tr class="title"><th colspan="7">'.$y.'年'.$m.'月</th></tr>';
        $html.='<tr><td>日</td><td>一</td><td>二</td><td>三</td><td>四</td><td>五</td><td>六</td>';
        $max=date('t',  strtotime("$y-$m"));
        $html.='<tr>';
        for($d=1;$d<=$max;++$d){
            if($w&&$d==1){
                $html.="<td colspan=\"$w\"></td>";
            }
            $html.="<td>$d</td>";
            if($w==6&&$d!=$max){
                $html.='</tr><tr>';
            }elseif($d==$max){
                $html.='<tr>';
            }
            $w=($w+1>6)?0:$w+1;
        }
        $html.='</table>';
    }
    return $html;
}
echo calendar('2021');
?>
<!doctype html>
<html>
    <head>
    <title>年历</title>
    <style>
  body{text-align:center;}
  .box{margin:0 auto;width:880px;}
  .title{background:#ccf;}
  table{height:200px;width:200px;font-size:12px;text-align:center;float:left;margin:10px;font-family:arial;}
    </style>
    </head>
    <body>
        
    </body>
</html>